Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(crypto): CRP-2597 Extend NiDkgTag with HighThresholdForKey variant #2445

Draft
wants to merge 36 commits into
base: franzstefan/CRP-2597-move-masterpublickeyid-proto-to-types
Choose a base branch
from

Conversation

fspreiss
Copy link
Member

@fspreiss fspreiss commented Nov 5, 2024

Extends the NiDkgTag with a new variant NiDkgTag::HighThresholdForKey that holds a MasterPublicKeyId.

Notes:

  • Makes the representation for NiDkgTag explicit with #[repr(isize)] because a #[repr(inttype)] must be provided on an enum if it has a non-unit variant with a discriminant (E0732). The representation should be the same as it was before, given that isize is the default representation for enums.

    Note that casting NiDkgTag with as, e.g., to i32 or even isize is no longer possible because "an as expression can be used to convert enum types to numeric types only if the enum type is unit-only or field-less" (see Enumeration casting and E0605).

  • The conversion impl TryFrom<i32> for NiDkgTag had to be removed, because it is no longer possible, because an i32 itself is no longer sufficient for instantiating an NiDkgTag.

    This conversion was used in two places: (1) impl TryFrom<NiDkgIdProto> for NiDkgId and (2) build_tagged_transcripts_map. There, the conversion is now implemented directly.

  • No longer Implements EnumIter for NiDkgTag because this would require a Default implementation for MasterPublicKeyId, which does not make sense, at least in production. Instead implements EnumCount.

TODOs:

  • Naming: NiDkgTag::HighThresholdForKey vs NiDkgTag::HighThresholdForKeyId
  • decide how to deal with #[allow(clippy::result_large_err)] in crypto code

@github-actions github-actions bot added the feat label Nov 5, 2024
@fspreiss fspreiss changed the base branch from franzstefan/CRP-2597-move-masterpublickeyid-proto-to-types-ontopof-non-copy-ni-dkg-id to franzstefan/CRP-2597-move-masterpublickeyid-proto-to-types November 6, 2024 08:38
@fspreiss fspreiss changed the title feat(crypto): CRP-2597-extend-nidkg-tag-with-high-threshold-for-keyid-variant feat(crypto): CRP-2597 Extend NiDkgTag with HighThresholdForKey variant Nov 6, 2024
Comment on lines +330 to +335
NiDkgTag::HighThresholdForKey(master_public_key_id) => {
error!(
log,
"Implementation error: NiDkgTag::HighThresholdForKey({master_public_key_id}) used in SetupInitialDKG for callback ID {callback_id}",
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idea here is to reuse the transcripts_for_remote_subnets field also for xnet reshares of VetKD keys. So then we would generalize this function such that it can generate the correct ConsensusResponse, depending on whether the callback ID is for a SetupInitialDKG context or a VetKD reshare context.

For now, logging an error and linking the ticket to generalize this function (CON-1416) should be fine.

Comment on lines +510 to +524
////////////////////////////////////////////////////////////////////////////////
// TODO: how to behave here? The code below is copied+adapted from the HighThreshold case. However,
// this code currently won't be executed because we iterate over TAGS, which is a const that does not
// and cannot contain an NiDkgTag::HighThresholdForKey entry
///////////////////////////////////////////////////////////////////////////////
NiDkgTag::HighThresholdForKey(master_public_key_id) => {
let resharing_transcript = reshared_transcripts
.get(&NiDkgTag::HighThresholdForKey(master_public_key_id.clone()));
(
resharing_transcript
.map(|transcript| transcript.committee.get().clone())
.unwrap_or_else(|| node_ids.clone()),
resharing_transcript.cloned(),
)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the behavior is correct (maybe it could even be combined with the NiDkgTag::HighThreshold branch). We can link ticket CON-1413 above, reminding us to iterate over all vetKD keys that were requested by registry in addition to the tags in TAGS.

Comment on lines +1227 to +1230
/////////////////////////////////////////
// TODO: check with Consensus team
NiDkgTag::HighThresholdForKey(_) => panic!("not applicable"),
/////////////////////////////////////////
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can link CON-1417 to extend this test once we have support for vet key transcripts in registry CUPs

Comment on lines +1336 to 1340
/////////////////////////////////////////
// TODO: check with Consensus team
NiDkgTag::HighThresholdForKey(_) => panic!("not applicable"),
/////////////////////////////////////////
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can link CON-1413 to extend this test once we can create local transcript configs for vetKeys that were requested by registry

)
})?;
////////////////////////////////////////////////////////
// TODO: Consensus team to decide if we should rather
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can leave it as is for now, but in the future we should probably just replace pb::TaggedNiDkgTranscript with pb::NiDkgTranscript since storing the tag (and key Id) twice is redundant. But this would require working around the cup_compatibilty_test some more, so I think we can handle this in a separate consensus ticket.

))
})?,
/////////////////////////////////////////////////
// TODO: ideally we extend existing tests where build_tagged_transcripts_map
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be that there are no specific unit tests for the (de)serialization of general summaries, and that this is only tested by system/integration tests. For IDKG we have test_summary_proto_conversion, probably it makes sense to add something similar for vet KD once that is possible.

It will also be tested as part of the cup_compatibility_test but only once we include the new variant in the ExhaustiveSet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants